<template>
      <div class="box">
        <RouterView/>
        <div class="bar">
          <div @click="handler(item.id)" :class="['item', item.isActive? 'is-active':'']"  v-for="item in list" :key="item.id">
            <span class="item-icon" :class="item.icon"></span>
            <span><RouterLink class="RL" :to="item.url">{{ item.label }}</RouterLink></span>
          </div>
        </div>
      </div>    
</template>

<script setup>
import { ref } from 'vue';
import  { nanoid } from 'nanoid';

const list = ref([
  {
    id: nanoid(6),
    label: '购物车',
    icon: 'far fa-address-book',
    isActive: false,
    url:'/01'
  },
  {
    id: nanoid(6),
    label: '收 藏',
    icon: 'far fa-chart-bar',
    isActive: false,
    url:'/02'
  },
  {
    id: nanoid(6),
    label: '首 页',
    icon: 'far fa-building',
    isActive: true,
    url:'/03'
  },
  {
    id: nanoid(6),
    label: '设 置',
    icon: 'fas fa-cog',
    isActive: false,
    url:'/04'
  },
  {
    id: nanoid(6),
    label: '我 的',
    icon: 'far fa-grin-alt',
    isActive: false,
    url:'/05'
  }
]);

const handler = id => {
  list.value.forEach( item => {
    item.isActive = item.id == id;
  } );
}

</script>

<style lang="scss" scoped>
 .box {
  width: 100%;
  height: 500vh;
  text-align: center;
 }

 .is-active {
  color: blue;
 }

 .bar {
  position: fixed;
  bottom: 0px;

  display: flex;
  justify-content: space-evenly;
  align-items: center;

  width: 100%;
  box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.3);

 }

 .item {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
 
  padding: 15px;
    &-icon {
      font-size: 25px;
    }
 }
.RL{
  
  text-decoration: none;
  color: #000;
}
</style>